package com.lalilu.homework6.fragment;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.lalilu.homework6.R;

public class Fragment_2 extends Fragment {

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        Button button_browser = view.findViewById(R.id.button_browser);
        Button button_bilibili = view.findViewById(R.id.button_bilibili);
        Button button_wechat = view.findViewById(R.id.button_wechat);

        button_browser.setOnClickListener((vw) -> {
            Intent intent = new Intent();
            intent.setAction("android.intent.action.VIEW");
            intent.setData(Uri.parse("https://baidu.com"));
            requireActivity().startActivity(intent);
        });

        button_bilibili.setOnClickListener((vw) -> {
            Intent intent = requireActivity().getPackageManager().getLaunchIntentForPackage("tv.danmaku.bili");
            requireActivity().startActivity(intent);
        });

        button_wechat.setOnClickListener((vw) -> {
            Intent intent = requireActivity().getPackageManager().getLaunchIntentForPackage("com.tencent.mm");
            requireActivity().startActivity(intent);
        });

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_2, container, false);
    }
}